gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\generalp\randpds.m
function [C]=randpds(dim,diagm) % [C]=randpds(dim,diagm) % % RANDPDS generates random positive definite symetric matrix of % given dimension. % % Input: % dim [1x1] given dimension of desired matrix. % diagm [1x1] if diagm==1 then then diagonal matrix is generated. % % Output: % C [dim x dim] positive definite symetric matrix. % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) % Modifications % 26-feb-2001 V.Franc if nargin < 2, diagm=0; end if diagm==0, %%%%%%%%%%%%% % creates randomly lowwer triangual matrix T with non-zero % members on diagonal T=rand(dim)*2-1+diag(rand(dim,1)*10-1); for j=1:dim-1, for i=j+1:dim, T(j,i)=0; end end % ensures that any diagonal member woun't be zero for i=1:dim, while T(i,i)==0, T(i,i)=rand(1)*2-1; end end %%%%%%%%%% % makes orthonormal R R=orth(T); %%%%%%%%%%%%%% % creates diag. matrix with positive members on diagonal D=diag(rand(1,dim)); %%%%%%%%%%%%%%%%%5 % creates Random Positive Definite Symetric Matrix C=R'*D*R; %%%% % the following line is due to numerical troubles if rank(C)~=dim, C=randpds(dim); end else %%%% C=diag(rand(dim,1)); end return